$files = `ls ./results_permutation_PVAL/`;
@files = split("\n",$files);
#print "@files\n";
open(BUFF,"SNP.txt");
$line=<BUFF>;
while(<BUFF>)
{
	chomp($_);
	@array = split("\t",$_);
	#print $array[0]."\n";
	$hash{$array[0]} =1;
}
for($i=0;$i<@files;$i++)
{
	open(BUFF,"./results_permutation_PVAL/$files[$i]") or die "no file $files[$i] found\n";
	open(WRBUFF,">./results_permutation_PVAL_filtered/$files[$i]") or die "not able to write file $files[$i] found\n";
	$line=<BUFF>;
	print WRBUFF $line;
	while(<BUFF>)
	{
        	chomp($_);
		$_ =~ s/"//g;
        	@array = split("\t",$_);
		#print "$array[0]\n";
		if(exists($hash{$array[0]}))
		{
			print WRBUFF $_."\n";
		}
	}
}
